// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: gekim

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>
#include <unordered_map>

#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::lbank::feed_v2 {
namespace impl {
using namespace coin2::exchange::base::symbology;


static std::unordered_map<std::string, std::string> TYPE_CHANNEL_MAP = {
    {"depth10", "books"},
    {"depth50", "books50"},
    {"incrdepth100", "increment_depth"},    
    {"tick", "ticker"},
    {"trade", "trade"},
    {"kbar1min", "kline_ws_1min"},
    {"kbar5min", "kline_ws_5min"},
    {"kbar15min", "kline_ws_15min"},
    {"kbar1hr", "kline_ws_1hour"},
    {"kbarday", "kline_ws_1day"},
    {"kline_rest", "kline_rest"},
};

struct LbankChannel {
  std::string channel;

  static LbankChannel Parse(const std::string& type) {
    auto pos = TYPE_CHANNEL_MAP.find(type);
    if (pos == TYPE_CHANNEL_MAP.end()) {
      return LbankChannel{};
    }
    return LbankChannel{pos->second};
  }
};

class LbankFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit LbankFeedProcessor(
    const std::string& system_name,
    const coin2::exchange::di::ConstantInjection& ci,
    const feed::RawParserConfig& config)
    : FeedParsingProcessor(
        system_name,
        MarketExchangeApi{MarketType::Spot, ExchangeType::Lbank, "v2"},
        ci, config,
        "cc/coin2/exchange/lbank/feed_v2/schema.json") {
  }

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
};

}  // namespace impl
using impl::LbankFeedProcessor;
}  // namespace coin2::exchange::lbank::feed_v2
